﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.utils.*;
    import com.tudou.skin.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;

    public class FinishTitleSprite extends Sprite implements ITransFinished, IPlayComplete
    {
        private var _playListSingleContinue:Boolean;
        private var _titleEnd:String = "</b></font>";
        private var line2:DisplayObject;
        private var _titleStart:String = "<font size=\'15\' color=\'#FF6600\' face=\'宋体\'><b>";
        private var totalHeight:Number = 0;
        private var checkboxTitle:TextField;
        private var _checkboxBtn:CheckboxBTN;
        private var _checkboxedBtn:CheckboxedBTN;
        private var title:TextField;
        private var totalWidth:Number = 0;
        private var _titleStr:String = "<font size=\'15\' color=\'#ADADAD\' face=\'宋体\'><b> 秒后即将播出</b></font>";
        private var _titleTimer:Timer;
        private var _titleCountDown:int = 6;
        private var _showTransFinished:Boolean = false;

        public function FinishTitleSprite()
        {
            totalWidth = NewSkinConsts.SHARE_WIDTH;
            title = TextFieldUtil.getTextField();
            addChild(title);
            title.htmlText = _titleStart + _titleCountDown.toString() + _titleEnd + _titleStr;
            var _loc_1:Number = 20;
            var _loc_2:Number = 10;
            totalHeight = _loc_1 + _loc_2 * 2 + 10;
            line2 = new PlayCompleteLine2MC();
            line2.x = int((totalWidth - line2.width) / 2);
            line2.y = _loc_1 + _loc_2;
            addChild(line2);
            RectDisplayUtil.drawRect(graphics, totalWidth, totalHeight, 0, 0);
            _titleTimer = new Timer(1000, _titleCountDown);
            _titleTimer.addEventListener(TimerEvent.TIMER, titleTimerHlr);
            _titleTimer.addEventListener(TimerEvent.TIMER_COMPLETE, titleTimerCompleteHlr);
            checkboxTitle = TextFieldUtil.getTextField();
            checkboxTitle.defaultTextFormat = new TextFormat("宋体", 12, 11382189, false);
            addChild(checkboxTitle);
            checkboxTitle.text = "自动播放下一个";
            checkboxTitle.x = totalWidth - checkboxTitle.width - 15;
            checkboxTitle.y = 1;
            _checkboxedBtn = new CheckboxedBTN();
            addChild(_checkboxedBtn);
            _checkboxedBtn.addEventListener(MouseEvent.CLICK, checkboxedHlr);
            _checkboxedBtn.x = checkboxTitle.x - _checkboxedBtn.width - 5;
            _checkboxedBtn.y = 3;
            _checkboxBtn = new CheckboxBTN();
            addChild(_checkboxBtn);
            _checkboxBtn.addEventListener(MouseEvent.CLICK, checkboxHlr);
            _checkboxBtn.x = _checkboxedBtn.x;
            _checkboxBtn.y = _checkboxedBtn.y;
            return;
        }// end function

        public function startTransFinishTimeout() : void
        {
            if (_showTransFinished)
            {
                if (_playListSingleContinue)
                {
                    title.htmlText = _titleStart + _titleCountDown.toString() + _titleEnd + _titleStr;
                    _titleTimer.start();
                    _checkboxBtn.visible = false;
                }
                else
                {
                    _checkboxedBtn.visible = false;
                    title.htmlText = " ";
                }
            }
            return;
        }// end function

        public function showComplete() : void
        {
            startTransFinishTimeout();
            return;
        }// end function

        private function titleTimerHlr(event:TimerEvent) : void
        {
            title.htmlText = _titleStart + (_titleCountDown - _titleTimer.currentCount).toString() + _titleEnd + _titleStr;
            return;
        }// end function

        public function setPlaylistSingleContinue(param1:Boolean) : void
        {
            _playListSingleContinue = param1;
            return;
        }// end function

        private function titleTimerCompleteHlr(event:TimerEvent) : void
        {
            FullScreen.getInst().exitFullScreen();
            SingleItemOpenUrl.openType = SingleItemOpenUrl.TRANS_FINISH_AUTO;
            dispatchEvent(new SkinEvent(SkinEvent.SINGLE_NEXT_INDEX));
            return;
        }// end function

        private function checkboxHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.SET_PLAYLIST_SINGLE_CONTINUE, true));
            _checkboxBtn.visible = false;
            _checkboxedBtn.visible = true;
            startTransFinishTimeout();
            return;
        }// end function

        public function stopTransFinishTimeout() : void
        {
            _titleTimer.stop();
            _titleTimer.reset();
            return;
        }// end function

        public function set showTransFinished(param1:Boolean) : void
        {
            _showTransFinished = param1;
            return;
        }// end function

        private function checkboxedHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkinEvent(SkinEvent.SET_PLAYLIST_SINGLE_CONTINUE, false));
            _checkboxedBtn.visible = false;
            _checkboxBtn.visible = true;
            stopTransFinishTimeout();
            title.htmlText = " ";
            return;
        }// end function

        public function hideComplete() : void
        {
            stopTransFinishTimeout();
            return;
        }// end function

    }
}
